package com.mbyte.easy.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mbyte.easy.admin.entity.*;
import com.mbyte.easy.admin.mapper.AllotMapper;
import com.mbyte.easy.admin.mapper.GroupMapper;
import com.mbyte.easy.admin.mapper.VideoMapper;
import com.mbyte.easy.admin.service.*;
import com.mbyte.easy.common.constant.DraftLogConstant;
import com.mbyte.easy.common.constant.StatusRecordVideo;
import com.mbyte.easy.common.constant.StatusWriter;
import com.mbyte.easy.common.constant.SysRole;
import com.mbyte.easy.common.controller.BaseController;
import com.mbyte.easy.common.web.AjaxResult;
import com.mbyte.easy.security.entity.SysUser;
import com.mbyte.easy.security.service.IUserService;
import com.mbyte.easy.util.DateUtil;
import com.mbyte.easy.util.OssUtil;
import com.mbyte.easy.util.PageInfo;
import com.mbyte.easy.util.Utility;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* <p>
* 前端控制器
* </p>
* @author lp
* @since 2019-03-11
*/
@Slf4j
@Controller
@RequestMapping("/admin/video/")
public class VideoController extends BaseController  {

    private String prefix = "admin/video/";

    @Autowired
    private IVideoService videoService;

    @Autowired
    private IAllotService allotService;

    @Autowired
    private ICheckService checkService;

    @Autowired
    private IAudioService audioService;
    @Autowired
    private IDraftService draftService;
    @Autowired
    private IGroupService groupService;

     @Autowired
    private IUserService userService;
     @Autowired
     private IPptService pptService;

     @Autowired
     private VideoMapper videoMapper;

     @Autowired
     private AllotMapper allotMapper;

     @Autowired
     private GroupMapper groupMapper;

    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    /**
    * 查询列表
    *
    * @param model
    * @param pageNo
    * @param pageSize
    * @param video
    * @return
    */
    @RequestMapping
    public String index(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
        if(!ObjectUtils.isEmpty(video.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id",video.getDraftId());
         }
        if(!ObjectUtils.isEmpty(video.getDraftType())) {
            queryWrapper = queryWrapper.like("draft_type",video.getDraftType());
         }
        if(!ObjectUtils.isEmpty(video.getVideoUrl())) {
            queryWrapper = queryWrapper.like("video_url",video.getVideoUrl());
         }
        if(!ObjectUtils.isEmpty(video.getVideoLength())) {
            queryWrapper = queryWrapper.like("video_length",video.getVideoLength());
         }
        if(!ObjectUtils.isEmpty(video.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time",video.getSubmitTime());
         }
        if(!ObjectUtils.isEmpty(video.getVideoMaker())) {
            queryWrapper = queryWrapper.like("video_maker",video.getVideoMaker());
         }
        if(!ObjectUtils.isEmpty(video.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code",video.getStatusCode());
         }
        if(!ObjectUtils.isEmpty(video.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete",video.getIsDelete());
         }
        if(!ObjectUtils.isEmpty(video.getAllotTime())) {
            queryWrapper = queryWrapper.like("allot_time",video.getAllotTime());
         }
        IPage<Video> pageInfo = videoService.page(page, queryWrapper);
        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("allotTimeSpace", allotTimeSpace);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix+"list";
    }

    /**
    * 添加跳转页面
    * @return
    */
    @GetMapping("addBefore")
    public String addBefore(){
        return prefix+"add";
    }
    /**
    * 添加
    * @param video
    * @return
    */
    @PostMapping("add")
    @ResponseBody
    public AjaxResult add(Video video){
        return toAjax(videoService.save(video));
    }

    /**
     *
     * 放大镜预览
    * 添加跳转页面
    * @return
    */
    @GetMapping("lastPreview/{id}")
    public String editBefore(Model model, @PathVariable("id") Long id
            ,String realseFlag,String buttonFlag,String checkFlag
            ,String reasonFlag,String agreeFlag,String rejectFlag
            ,String firstFlag,String pptUpload,String audioUpload
            ,String audioRealseFlag,String code,String oneFlag,String updateFlag){

        Draft draft = draftService.getById(id);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Video::getDraftId, id);
        Video video = videoService.getOne(queryWrapper);
        if (video != null) {
            model.addAttribute("video", video);
            showReason(model,video);

             //wangyan 显示制作人名称
            List<Video> draftList = videoMapper.selectList(queryWrapper);
            Map<Long, String> types = new HashMap<Long, String>();
            List<Long> ids = new ArrayList<>();
            for (Video video1 : draftList) {
                if (!ids.contains(video1.getVideoMaker())) {
                    ids.add(video1.getVideoMaker());
                    types.put(video1.getVideoMaker(), userService.selectByPrimaryKey(video1.getVideoMaker()).getUsername());
                }
            }
            model.addAttribute("name", types);

        }
        QueryWrapper<Audio> queryWrapperAudio = new QueryWrapper<>();
        queryWrapperAudio.lambda().eq(Audio::getDraftId, id);
        Audio audio = audioService.getOne(queryWrapperAudio);
        if (audio != null) {
            model.addAttribute("audio", audio);
        }
        QueryWrapper<Ppt> queryWrapperPpt = new QueryWrapper<>();
        queryWrapperPpt.lambda().eq(Ppt::getDraftId, id);
        Ppt ppt = pptService.getOne(queryWrapperPpt);
        if (ppt != null) {
            model.addAttribute("ppt", ppt);
        }
        log.info("oneFlage" + oneFlag);
        model.addAttribute("updateFlag",updateFlag);
        model.addAttribute("code",code);
        model.addAttribute("audioUpload",audioUpload);
        model.addAttribute("audioRealseFlag",audioRealseFlag);
        model.addAttribute("pptUpload",pptUpload);
        model.addAttribute("realseFlag",realseFlag);
        model.addAttribute("firstFlag",firstFlag);
        model.addAttribute("agreeFlag",agreeFlag);
        model.addAttribute("rejectFlag",rejectFlag);
        model.addAttribute("buttonFlag",buttonFlag);
        model.addAttribute("checkFlag",checkFlag);
        model.addAttribute("reasonFlag",reasonFlag);
        model.addAttribute("draft",draft);
        model.addAttribute("oneFlag",oneFlag);
        applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_LOOK)
                .setDraftId(id));
        return prefix+"last-preivew";
}

    private void showReason(Model model,Video video){
        List<Check> checkList = checkService.list(new QueryWrapper<Check>().lambda()
                .eq(Check::getDraftId,video.getId())
                .eq(Check::getUserId,video.getLastOperator())
                .orderByDesc(Check::getCreateTime));
        String reason = null;
        if(!CollectionUtils.isEmpty(checkList)){
            reason = checkList.get(0).getReason();
        }
        model.addAttribute("reason",reason);
    }

    /**
    * 添加
    * @param video
    * @return
    */
    @PostMapping("edit")
    @ResponseBody
    public AjaxResult edit(Video video){
        return toAjax(videoService.updateById(video));
    }
    /**
    * 删除
    * @param id
    * @return
    */
    @GetMapping("delete/{id}")
    @ResponseBody
    public AjaxResult delete(@PathVariable("id") Long id){
        return toAjax(videoService.removeById(id));
    }
    /**
    * 批量删除
    * @param ids
    * @return
    */
    @PostMapping("deleteAll")
    @ResponseBody
    public AjaxResult deleteAll(@RequestBody List<Long> ids){
        return toAjax(videoService.removeByIds(ids));
    }

    /**
     * @Author 张雪
     * @Description 制作人 审核中音转视
     * @Date 2019/12/17 15:48
     * @Param
     * @return
     **/
    @RequestMapping("checkingVideo")
    public String checkingAudioVideo(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                     String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
        if(!ObjectUtils.isEmpty(video.getDraftId())) {

            queryWrapper = queryWrapper.like("draft_id",video.getDraftId());
        }
        if(!ObjectUtils.isEmpty(video.getDraftType())) {
            queryWrapper = queryWrapper.like("draft_type",video.getDraftType());
        }
        if(!ObjectUtils.isEmpty(video.getVideoUrl())) {
            queryWrapper = queryWrapper.like("video_url",video.getVideoUrl());
        }
        if(!ObjectUtils.isEmpty(video.getVideoLength())) {
            queryWrapper = queryWrapper.like("video_length",video.getVideoLength());
        }
        if(!ObjectUtils.isEmpty(video.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time",video.getSubmitTime());
        }
        if(!ObjectUtils.isEmpty(video.getVideoMaker())) {
            queryWrapper = queryWrapper.like("video_maker",video.getVideoMaker());
        }
        if(!ObjectUtils.isEmpty(video.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code",video.getStatusCode());
        }
        if(!ObjectUtils.isEmpty(video.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete",video.getIsDelete());
        }
        if(!ObjectUtils.isEmpty(video.getAllotTime())) {
            queryWrapper = queryWrapper.like("allot_time",video.getAllotTime());
        }
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        queryWrapper.lambda().orderByDesc(Video::getCreateTime);
        String username = Utility.getCurrentUsername();
        queryWrapper.eq("tv.video_maker", userService.selectByUsername(username).getId());
        queryWrapper.eq("tv.status_code", StatusRecordVideo.STATUS_VIDEO_AUDIOTOVIDEO_UPLOAD);
//        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);
        IPage<Video> pageInfo = videoService.listPage(page, queryWrapper);
        PageInfo pageInfo1 = new PageInfo(pageInfo);
        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", pageInfo1);
        return prefix + "both/checkingVideo";

    }

    /**
     * @Author 张雪
     * @Description 音转视校对人--已通过音转视
     * @Date 2019/12/18 15:48
     * @Param
     * @return
     **/
    @RequestMapping("overVideo")
    public String overVideo(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1")
            Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                            String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
        if(!ObjectUtils.isEmpty(video.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id",video.getDraftId());
        }
        if(!ObjectUtils.isEmpty(video.getDraftType())) {
            queryWrapper = queryWrapper.like("draft_type",video.getDraftType());
        }
        if(!ObjectUtils.isEmpty(video.getVideoUrl())) {
            queryWrapper = queryWrapper.like("video_url",video.getVideoUrl());
        }
        if(!ObjectUtils.isEmpty(video.getVideoLength())) {
            queryWrapper = queryWrapper.like("video_length",video.getVideoLength());
        }
        if(!ObjectUtils.isEmpty(video.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time",video.getSubmitTime());
        }
        if(!ObjectUtils.isEmpty(video.getVideoMaker())) {
            queryWrapper = queryWrapper.like("video_maker",video.getVideoMaker());
        }
        if(!ObjectUtils.isEmpty(video.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code",video.getStatusCode());
        }
        if(!ObjectUtils.isEmpty(video.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete",video.getIsDelete());
        }
        if(!ObjectUtils.isEmpty(video.getAllotTime())) {
            queryWrapper = queryWrapper.like("allot_time",video.getAllotTime());
        }
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        String currentUsername = Utility.getCurrentUsername();
//        queryWrapper.lambda().eq(Video::getVideoMaker, userService.selectByUsername(currentUsername).getId());

        //分配表中被分配人id为自己的draftIds
        Long cuurentUserId = videoService.selectUserIdByUsername(Utility.getCurrentUsername());
        QueryWrapper<Allot> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.in("allotNo_id", cuurentUserId);
        List<Allot> allotList = allotService.list(queryWrapper1);
        if (allotList.size() != 0) {
            List<Long> draftIds = new ArrayList<>();
            for (int i = 0; i < allotList.size(); i++) {
                draftIds.add(allotList.get(i).getDraftId());
            }

            queryWrapper.in("tv.status_code", StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_SUCCESS,
                    StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS);//1023音频校对人通过
            queryWrapper.eq("tv.draft_type",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE1);
            queryWrapper.in("tv.draft_id", draftIds);

        }else{
            queryWrapper.eq("tv.status_code", StatusWriter.ERROR);
        }

        IPage<Video> pageInfo = videoService.listPage(page, queryWrapper);
        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("allotTimeSpace", allotTimeSpace);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix+"audio/overVideo";
    }



    /**
     * @Author 张雪
     * @Description 制作人--被驳回音转视
     * @Date 2019/12/18 15:48
     * @Param
     * @return
     **/
    @RequestMapping("refusedMaker")
    public String refusedMaker(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1")
            Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20")
            Integer pageSize, String submitTimeSpace,
                               String allotTimeSpace, String createTimeSpace, String updateTimeSpace,
                               Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
        if(!ObjectUtils.isEmpty(video.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id",video.getDraftId());
        }
        if(!ObjectUtils.isEmpty(video.getDraftType())) {
            queryWrapper = queryWrapper.like("draft_type",video.getDraftType());
        }
        if(!ObjectUtils.isEmpty(video.getVideoUrl())) {
            queryWrapper = queryWrapper.like("video_url",video.getVideoUrl());
        }
        if(!ObjectUtils.isEmpty(video.getVideoLength())) {
            queryWrapper = queryWrapper.like("video_length",video.getVideoLength());
        }
        if(!ObjectUtils.isEmpty(video.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time",video.getSubmitTime());
        }
        if(!ObjectUtils.isEmpty(video.getVideoMaker())) {
            queryWrapper = queryWrapper.like("video_maker",video.getVideoMaker());
        }
        if(!ObjectUtils.isEmpty(video.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code",video.getStatusCode());
        }
        if(!ObjectUtils.isEmpty(video.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete",video.getIsDelete());
        }
        if(!ObjectUtils.isEmpty(video.getAllotTime())) {
            queryWrapper = queryWrapper.like("allot_time",video.getAllotTime());
        }

        queryWrapper.lambda().orderByDesc(Video::getCreateTime);
        //分配表中被分配人id为自己的draftIds
        Long cuurentUserId = videoService.selectUserIdByUsername(Utility.getCurrentUsername());
        QueryWrapper<Allot> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.in("allotNo_id", cuurentUserId);
        List<Allot> allotList = allotService.list(queryWrapper1);
        if (allotList.size() > 0) {
            List<Long> draftIds = new ArrayList<>();
            for (int i = 0; i < allotList.size(); i++) {
                draftIds.add(allotList.get(i).getDraftId());
            }
            List<Audio> audioList = audioService.list(new QueryWrapper<Audio>().lambda()
                    .in(Audio::getDraftId,draftIds));
            if(!CollectionUtils.isEmpty(audioList)){
                queryWrapper.in("tv.draft_id",audioList.stream().map(a->a.getDraftId()).collect(Collectors.toList()));
            }else{
                queryWrapper.in("tv.draft_id",-1L);
            }
            queryWrapper.in("tv.status_code", StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_FAILED, StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_FAILED, StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_FAILED);//2023音频校对人驳回

        }else{
            queryWrapper.eq("tv.status_code", StatusWriter.ERROR);

        }
        IPage<Video> pageInfo = videoService.listPage(page, queryWrapper);

        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("allotTimeSpace", allotTimeSpace);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix+"audio/failMaker";
    }


    /**
     * 查询列表
     *
     * @param model
     * @param pageNo
     * @param pageSize
     * @param video
     * @return
     */
    @RequestMapping("checkBefore")
    public String checkBefore(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
        if(!ObjectUtils.isEmpty(video.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id",video.getDraftId());
        }
        if(!ObjectUtils.isEmpty(video.getDraftType())) {
            queryWrapper = queryWrapper.like("draft_type",video.getDraftType());
        }
        if(!ObjectUtils.isEmpty(video.getVideoUrl())) {
            queryWrapper = queryWrapper.like("video_url",video.getVideoUrl());
        }
        if(!ObjectUtils.isEmpty(video.getVideoLength())) {
            queryWrapper = queryWrapper.like("video_length",video.getVideoLength());
        }
        if(!ObjectUtils.isEmpty(video.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time",video.getSubmitTime());
        }
        if(!ObjectUtils.isEmpty(video.getVideoMaker())) {
            queryWrapper = queryWrapper.like("video_maker",video.getVideoMaker());
        }
        if(!ObjectUtils.isEmpty(video.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code",video.getStatusCode());
        }
        if(!ObjectUtils.isEmpty(video.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete",video.getIsDelete());
        }
        if(!ObjectUtils.isEmpty(video.getAllotTime())) {
            queryWrapper = queryWrapper.like("allot_time",video.getAllotTime());
        }

        String currentUsername = Utility.getCurrentUsername();
        Long currentUserId = videoService.selectUserIdByUsername(currentUsername);
        Long groupId = videoService.selectGroupIdByUserId(currentUserId);
        log.info("登录用户对应groupId-->{}",groupId);
        queryWrapper.lambda().eq(Video::getGroupId,groupId).eq(Video::getStatusCode,StatusRecordVideo.STATUS_VIDEO_AUDIOTOVIDEO_UPLOAD);
        IPage<Video> pageInfo = videoService.page(page, queryWrapper);
        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("allotTimeSpace", allotTimeSpace);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix+"audio/check";
    }

    /**
     * @Author 张雪
     * @Description 校对人--待校对音转视
     * @Date 2019/12/17 15:48
     * @Param
     * @return
     **/
    @RequestMapping("unCheckAudioVideo")
    public String unCheckAudioVideo(Model model,
                                    @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                    @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                    String submitTimeSpace,
                                    String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
         Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
        if(!ObjectUtils.isEmpty(video.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id",video.getDraftId());
        }
        if(!ObjectUtils.isEmpty(video.getDraftType())) {
            queryWrapper = queryWrapper.like("draft_type",video.getDraftType());
        }
        if(!ObjectUtils.isEmpty(video.getVideoUrl())) {
            queryWrapper = queryWrapper.like("video_url",video.getVideoUrl());
        }
        if(!ObjectUtils.isEmpty(video.getVideoLength())) {
            queryWrapper = queryWrapper.like("video_length",video.getVideoLength());
        }
        if(!ObjectUtils.isEmpty(video.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time",video.getSubmitTime());
        }
        if(!ObjectUtils.isEmpty(video.getVideoMaker())) {
            queryWrapper = queryWrapper.like("video_maker",video.getVideoMaker());
        }
        if(!ObjectUtils.isEmpty(video.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code",video.getStatusCode());
        }
        if(!ObjectUtils.isEmpty(video.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete",video.getIsDelete());
        }
        if(!ObjectUtils.isEmpty(video.getAllotTime())) {
            queryWrapper = queryWrapper.like("allot_time",video.getAllotTime());
        }
        queryWrapper.lambda().orderByDesc(Video::getCreateTime);
        SysUser sysUser = videoService.getUserByUserName(Utility.getCurrentUsername());
        List<Allot> groupByUserId = videoService.getAllotDraftIdByUserId(sysUser.getId());
        if (groupByUserId.size() != 0) {
            if (!ObjectUtils.isEmpty(submitTimeSpace)){
                queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                        ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
            }
            queryWrapper.in("tv.draft_id",groupByUserId.stream().map(Allot::getDraftId).collect(Collectors.toList()));
            queryWrapper.eq("tv.status_code", StatusRecordVideo.STATUS_VIDEO_AUDIOTOVIDEO_UPLOAD)
                    .eq("tv.draft_type",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE1);//1019
            IPage<Video> pageInfo = videoService.listPage(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "audio/unCheckAudioVideo";
        }else {
            queryWrapper.lambda().eq(Video::getStatusCode, StatusWriter.ERROR);
            IPage<Video> pageInfo = videoService.page(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix + "audio/unCheckAudioVideo";
        }


//        //分配表中被分配人id为自己的draftIds
//        Long cuurentUserId = videoService.selectUserIdByUsername(Utility.getCurrentUsername());
//        QueryWrapper<Allot> queryWrapper1 = new QueryWrapper<>();
//        queryWrapper1.in("allotNo_id", cuurentUserId);
//        List<Allot> allotList = allotService.list(queryWrapper1);
//        if (allotList.size() != 0) {
//            List<Long> draftIds = new ArrayList<>();
//            for (int i = 0; i < allotList.size(); i++) {
//                draftIds.add(allotList.get(i).getDraftId());
//            }
//            log.info("draftIds-->{}", draftIds);
//            queryWrapper.in("draft_id", draftIds);
//            queryWrapper.lambda().
//                    eq(Video::getStatusCode, StatusRecordVideo.STATUS_VIDEO_AUDIOTOVIDEO_UPLOAD);//1019校对人待校对音转视
//            queryWrapper.lambda().orderByDesc(Video::getCreateTime);
//            IPage<Video> pageInfo = videoService.page(page, queryWrapper);
//            model.addAttribute("submitTimeSpace", submitTimeSpace);
//            model.addAttribute("allotTimeSpace", allotTimeSpace);
//            model.addAttribute("searchInfo", video);
//            model.addAttribute("pageInfo", new PageInfo(pageInfo));
//            return prefix + "audio/unCheckAudioVideo";
//        }else{
//            queryWrapper.lambda().eq(Video::getStatusCode, StatusWriter.ERROR);
//            queryWrapper.lambda().orderByDesc(Video::getCreateTime);
//            IPage<Video> pageInfo = videoService.page(page, queryWrapper);
//            model.addAttribute("submitTimeSpace", submitTimeSpace);
//            model.addAttribute("allotTimeSpace", allotTimeSpace);
//            model.addAttribute("searchInfo", video);
//            model.addAttribute("pageInfo", new PageInfo(pageInfo));
//            return prefix + "audio/unCheckAudioVideo";
//        }
    }

    /**
     * @Author 刘辉
     * @Description 课程校对人--待校对录屏
     * @Date 2019/12/17 15:48
     * @Param
     * @return
     **/
    @RequestMapping("unCheckPptVideo")
    public String unCheckPptVideo(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
         if (!ObjectUtils.isEmpty(submitTimeSpace)){
        queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);

        Long currentUserId = pptService.selectIdByUsername(Utility.getCurrentUsername());
        //分配表中id为自己的稿件id
        QueryWrapper<Allot> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("allotNo_id", currentUserId);
        List<Allot> allotList = allotService.list(queryWrapper1);
        List<Long> draftIds = new ArrayList<>();
        if (allotList.size()!=0){
            for (int i = 0; i < allotList.size(); i++) {
                draftIds.add(allotList.get(i).getDraftId());
            }
            queryWrapper.in("tv.draft_id", draftIds);
            queryWrapper.eq("tv.status_code",StatusRecordVideo.STATUS_RECORD_AUVELEADER_DISTRIBUTION);//1037
            queryWrapper.in("tv.draft_type",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE2);

            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"ppt/unCheckPptVideo";
        }else {
            queryWrapper.eq("tv.status_code", StatusWriter.ERROR);
            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"ppt/unCheckPptVideo";
        }
    }

    /**
     * 张雪
     * 通过校对--音转视
     * @param id
     * @return
     */
    @GetMapping("passAudioVideo")
    @ResponseBody
    public AjaxResult passAudioVideo(@RequestParam("id") Long id,String draftText,String draftTitle,Long draftNum,String fileName){
        Draft draft = draftService.getById(videoService.getById(id).getDraftId());
        draft.setDraftText(draftText);
        draft.setDraftTitle(draftTitle);
        draft.setDraftNum(draftNum);
        draft.setFileName(fileName);
        draftService.updateById(draft);

        log.info("通过id-->{}",id);
        Video videoPass = new Video();
        log.info("draftService.selectRoleId()="+draftService.selectRoleId());
        if(draftService.selectRoleId() == SysRole.VIDEO_PROOFREADER) {
            videoPass.setStatusCode(StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_SUCCESS)//1023音频校对人通过
                    .setLastOperator(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                    .setIsPass(true).setId(id);
            videoService.updateById(videoPass);
            Check videoCheck = new Check();
            videoCheck.setIsPass(true).setUserId(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                    .setPreStatusCode(StatusRecordVideo.STATUS_VIDEO_AUDIOTOVIDEO_UPLOAD)
                    .setOverStatusCode(StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_SUCCESS)
                    .setDraftId(videoService.getById(id).getDraftId());
            checkService.save(videoCheck);

            applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_VIDEO)
                    .setDraftId((videoService.getById(id).getDraftId()))
                    .setGroupId(videoService.getById(id).getGroupId())
                    .setPrimaryState(StatusRecordVideo.STATUS_VIDEO_AUDIOTOVIDEO_UPLOAD)
                    .setAfterState(StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_SUCCESS));

        }else if(draftService.selectRoleId() == SysRole.AUDIO_VIDEO_CHECK_LEADER){
            videoPass.setStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS)//1025音频校对zuzhang通过
                    .setLastOperator(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                    .setIsPass(true).setId(id);
            videoService.updateById(videoPass);
            Check videoCheck = new Check();
            videoCheck.setIsPass(true).setUserId(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                    .setPreStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_FAILED)
                    .setOverStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS)
                    .setDraftId(videoService.getById(id).getDraftId());
            checkService.save(videoCheck);

            applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_VIDEO)
                    .setDraftId((videoService.getById(id).getDraftId()))
                    .setGroupId(videoService.getById(id).getGroupId())
                    .setPrimaryState(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_FAILED)
                    .setAfterState(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS));
        }
        log.info("update-->{}",videoPass.toString());

        return toAjax(true);
    }

     /**
     * 刘辉
     * 通过校对--录屏--课程校对人
     * @param id
     * @return
     */
    @GetMapping("passPptorVideo")
    @ResponseBody
    public AjaxResult passPptorVideo(@RequestParam("id") Long id,String draftTitle,String draftText,Long draftNum,String fileName){
        log.info("通过id-->{}",id);


        Draft draft = draftService.getById(videoService.getById(id).getDraftId());
        draft.setDraftText(draftText);
        draft.setDraftTitle(draftTitle);
        draft.setDraftNum(draftNum);
        draft.setFileName(fileName);
        draftService.updateById(draft);

        Video videoPass = new Video();
        videoPass.setStatusCode(StatusRecordVideo.STATUS_RECORD_COURSEREADER_SUCCESS)//1038 课程校对人通过录屏
                .setLastOperator(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                .setIsPass(true).setId(id);
        videoService.updateById(videoPass);


        String username = Utility.getCurrentUsername();
        SysUser sysUser = draftService.getUserIdByUserName(username);

        Group group= new Group();
        group.setGroupId(videoMapper.selectById(id).getGroupId());
        group.setUserId(sysUser.getId());
        groupMapper.updateByGroupId(group);

        QueryWrapper<Video> videolist=new QueryWrapper<>();
        videolist.eq("id", id);
        List<Video> videos=videoService.list(videolist);
           List<Long> ids = new ArrayList<>();
         for (Video video1 : videos) {
             ids.add(video1.getDraftId());
         }
        Allot allot=new Allot();
        allot.setDraftId(ids.get(0));
        allot.setStatusCode(StatusRecordVideo.STATUS_RECORD_COURSEREADER_SUCCESS);
        videoMapper.updateStatusCodeByDraftId(allot);

        Check videoCheck = new Check();
        videoCheck.setIsPass(true).setUserId(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                .setPreStatusCode(StatusRecordVideo.STATUS_RECORD_AUVELEADER_DISTRIBUTION)
                .setOverStatusCode(StatusRecordVideo.STATUS_RECORD_COURSEREADER_SUCCESS)
                .setDraftId(videoService.getById(id).getDraftId())
                .setCreateTime(LocalDateTime.now())
                .setUpdateTime(LocalDateTime.now());
        checkService.save(videoCheck);
        log.info("update-->{}",videoPass.toString());

         applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_CHECK_YES)
                    .setDraftId((videoService.getById(id).getDraftId()))
                    .setActionContent("课程校对人通过录屏")
                    .setGroupId(videoMapper.selectById(id).getGroupId())
                    .setPrimaryState(StatusRecordVideo.STATUS_RECORD_AUVELEADER_DISTRIBUTION)
                    .setAfterState(StatusRecordVideo.STATUS_RECORD_COURSEREADER_SUCCESS));
        return toAjax(true);
    }

    /**
     * 刘辉
     * 通过校对--录屏--音视频校对组长
     * @param id
     * @return
     */
    @GetMapping("passBossPptVideo")
    @ResponseBody
    public AjaxResult passBossPptVideo(@RequestParam("id") Long id,String draftTitle,String draftText,Long draftNum,String fileName){
        log.info("通过id-->{}",id);

      Draft draft = draftService.getById(videoService.getById(id).getDraftId());
        draft.setDraftText(draftText);
        draft.setDraftTitle(draftTitle);
        draft.setDraftNum(draftNum);
        draft.setFileName(fileName);
        draftService.updateById(draft);

        Video videoPass = new Video();
        videoPass.setStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS)//1038 课程校对人通过录屏
                .setLastOperator(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                .setIsPass(true).setId(id);
        videoService.updateById(videoPass);

        String username = Utility.getCurrentUsername();
        SysUser sysUser = draftService.getUserIdByUserName(username);

        Group group= new Group();
        group.setGroupId(videoMapper.selectById(id).getGroupId());
        group.setUserId(sysUser.getId());
        groupMapper.updateByGroupId(group);

        Check videoCheck = new Check();
        videoCheck.setIsPass(true).setUserId(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                .setPreStatusCode(StatusRecordVideo.STATUS_RECORD_COURSEREADER_SUCCESS)
                .setOverStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS)
                .setDraftId(videoService.getById(id).getDraftId())
                .setCreateTime(LocalDateTime.now())
                .setUpdateTime(LocalDateTime.now());
        checkService.save(videoCheck);
        log.info("update-->{}",videoPass.toString());

        applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_CHECK_YES)
                    .setDraftId((videoService.getById(id).getDraftId()))
                    .setGroupId(videoMapper.selectById(id).getGroupId())
                    .setActionContent("音视频校对组长通过录屏")
                    .setPrimaryState(StatusRecordVideo.STATUS_RECORD_COURSEREADER_SUCCESS)
                    .setAfterState(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS));

        return toAjax(true);
    }


    /**
     * 张雪
     * 校对拒绝--音转视校对人
     * @param id
     * @return
     */
    @PostMapping("refuseAudioVideo")
    @ResponseBody
    public AjaxResult refuseAudioVideo(Long id,String reason,String draftTitle,String draftText,Long draftNum,String fileName){

        Draft draft = draftService.getById(videoService.getById(id).getDraftId());
        draft.setDraftText(draftText);
        draft.setDraftTitle(draftTitle);
        draft.setDraftNum(draftNum);
        draft.setFileName(fileName);
        draftService.updateById(draft);


        log.info("拒绝id-->{}",id);
        Video videoRefuse = new Video();
        if(draftService.selectRoleId()==SysRole.VIDEO_PROOFREADER) {
            videoRefuse.setStatusCode(StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_FAILED)//2023音频校对人拒绝
                    .setLastOperator(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                    .setIsPass(false).setId(id);
            videoService.updateById(videoRefuse);
            Check videoCheck = new Check();
            videoCheck.setIsPass(false).setUserId(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                    .setPreStatusCode(StatusRecordVideo.STATUS_VIDEO_AUDIOTOVIDEO_UPLOAD)
                    .setOverStatusCode(StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_FAILED)
                    .setCreateTime(LocalDateTime.now()).setUpdateTime(LocalDateTime.now())
                    .setReason(reason).setDraftId(videoService.getById(id).getId()
            );
            checkService.save(videoCheck);

            applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_CHECK_NO)
                    .setDraftId(videoService.getById(id).getDraftId())
                    .setGroupId(videoService.getById(id).getGroupId())
                    .setPrimaryState(StatusRecordVideo.STATUS_VIDEO_AUDIOTOVIDEO_UPLOAD)
                    .setAfterState(StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_FAILED)
                    .setReason(reason));

        }else if(draftService.selectRoleId()==SysRole.AUDIO_VIDEO_CHECK_LEADER) {
            videoRefuse.setStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_FAILED)//2023音频校对人拒绝
                    .setLastOperator(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                    .setIsPass(false).setId(id);
            videoService.updateById(videoRefuse);
            Check videoCheck = new Check();
            videoCheck.setIsPass(false).setUserId(videoService.selectUserIdByUsername(Utility.getCurrentUsername()))
                    .setPreStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_FAILED)
                    .setOverStatusCode(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_FAILED)
                    .setCreateTime(LocalDateTime.now()).setUpdateTime(LocalDateTime.now())
                    .setReason(reason).setDraftId(videoService.getById(id).getId());
            checkService.save(videoCheck);

            applicationEventPublisher.publishEvent(new DraftLog().setActionType(DraftLogConstant.ACTION_CHECK_NO)
                    .setDraftId(videoService.getById(id).getDraftId())
                    .setGroupId(videoService.getById(id).getGroupId())
                    .setPrimaryState(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_FAILED)
                    .setAfterState(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_FAILED)
                    .setReason(reason));
        }
        return toAjax(true);
    }
    /**
     * 添加跳转页面
     * @return
     */
    @RequestMapping("toReason")
    public String toReason(Long id,Model model){
        log.info("id====>{}",id);
        model.addAttribute("id",id);
        return prefix+"audio/reason";
    }

    /**
     * @Author 张雪
     * @Description 校对人--被驳回音转视
     * @Date 2019/12/18 15:48
     * @Param
     * @return
     **/
    @RequestMapping("refusedLeader")
    public String refusedLeader(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
        if(!ObjectUtils.isEmpty(video.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id",video.getDraftId());
        }
        if(!ObjectUtils.isEmpty(video.getDraftType())) {
            queryWrapper = queryWrapper.like("draft_type",video.getDraftType());
        }
        if(!ObjectUtils.isEmpty(video.getVideoUrl())) {
            queryWrapper = queryWrapper.like("video_url",video.getVideoUrl());
        }
        if(!ObjectUtils.isEmpty(video.getVideoLength())) {
            queryWrapper = queryWrapper.like("video_length",video.getVideoLength());
        }
        if(!ObjectUtils.isEmpty(video.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time",video.getSubmitTime());
        }
        if(!ObjectUtils.isEmpty(video.getVideoMaker())) {
            queryWrapper = queryWrapper.like("video_maker",video.getVideoMaker());
        }
        if(!ObjectUtils.isEmpty(video.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code",video.getStatusCode());
        }
        if(!ObjectUtils.isEmpty(video.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete",video.getIsDelete());
        }
        if(!ObjectUtils.isEmpty(video.getAllotTime())) {
            queryWrapper = queryWrapper.like("allot_time",video.getAllotTime());
        }

        //分配表中被分配人id为自己的draftIds
        Long cuurentUserId = videoService.selectUserIdByUsername(Utility.getCurrentUsername());
        QueryWrapper<Allot> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.in("allotNo_id", cuurentUserId);
        List<Allot> allotList = allotService.list(queryWrapper1);
        List<Long> draftIds = new ArrayList<>();
        for (int i = 0; i <allotList.size() ; i++) {
            draftIds.add(allotList.get(i).getDraftId());
        }
        queryWrapper.in("draft_id",draftIds);

        queryWrapper.lambda()
                .or().eq(Video::getStatusCode,StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_FAILED)//2025视频校对组长驳回
                .or().eq(Video::getStatusCode,StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_FAILED);//2016音视频终审人驳回

        IPage<Video> pageInfo = videoService.page(page, queryWrapper);
        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("allotTimeSpace", allotTimeSpace);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix+"both/refusedLeader";
    }


    /**
     * @Author 张雪
     * @Description 校对人--已驳回校对音转视
     * @Date 2019/12/18 15:48
     * @Param
     * @return
     **/
    @RequestMapping("refusedWorker")
    public String refusedWorker(Model model,
                                @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                String submitTimeSpace, String allotTimeSpace,
                                Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<>();
        if(!ObjectUtils.isEmpty(video.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id",video.getDraftId());
        }
        if(!ObjectUtils.isEmpty(video.getDraftType())) {
            queryWrapper = queryWrapper.like("draft_type",video.getDraftType());
        }
        if(!ObjectUtils.isEmpty(video.getVideoUrl())) {
            queryWrapper = queryWrapper.like("video_url",video.getVideoUrl());
        }
        if(!ObjectUtils.isEmpty(video.getVideoLength())) {
            queryWrapper = queryWrapper.like("video_length",video.getVideoLength());
        }
        if(!ObjectUtils.isEmpty(video.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time",video.getSubmitTime());
        }
        if(!ObjectUtils.isEmpty(video.getVideoMaker())) {
            queryWrapper = queryWrapper.like("video_maker",video.getVideoMaker());
        }
        if(!ObjectUtils.isEmpty(video.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code",video.getStatusCode());
        }
        if(!ObjectUtils.isEmpty(video.getAllotTime())) {
            queryWrapper = queryWrapper.like("allot_time",video.getAllotTime());
        }
        if(!ObjectUtils.isEmpty(video.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete",video.getIsDelete());
        }
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        //分配表中被分配人id为自己的draftIds
        Long cuurentUserId = videoService.selectUserIdByUsername(Utility.getCurrentUsername());
        QueryWrapper<Allot> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.in("allotNo_id", cuurentUserId);
        List<Allot> allotList = allotService.list(queryWrapper1);
        if (allotList.size() != 0) {
            List<Long> draftIds = new ArrayList<>();
            for (int i = 0; i < allotList.size(); i++) {
                draftIds.add(allotList.get(i).getDraftId());
            }
            queryWrapper.in("tv.draft_id", draftIds)
                    .eq("tv.status_code", StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_FAILED);//2023音频校对人拒绝视频
        }else{
            queryWrapper.eq("tv.status_code", StatusWriter.ERROR);
        }
        queryWrapper.lambda().orderByDesc(Video::getCreateTime);
        IPage<Video> pageInfo = videoService.listPage(page, queryWrapper);

        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("allotTimeSpace", allotTimeSpace);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix+"both/refusedWorker";
    }

     /**
     * @Author 刘辉
     * @Description 校对人-- 被驳回音转视
     * @Param
     * @return
     **/
    @RequestMapping("alreadyRefusedWorker")
    public String alreadyRefusedWorker(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
        if(!ObjectUtils.isEmpty(video.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id",video.getDraftId());
        }
        if(!ObjectUtils.isEmpty(video.getDraftType())) {
            queryWrapper = queryWrapper.like("draft_type",video.getDraftType());
        }
        if(!ObjectUtils.isEmpty(video.getVideoUrl())) {
            queryWrapper = queryWrapper.like("video_url",video.getVideoUrl());
        }
        if(!ObjectUtils.isEmpty(video.getVideoLength())) {
            queryWrapper = queryWrapper.like("video_length",video.getVideoLength());
        }
        if(!ObjectUtils.isEmpty(video.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time",video.getSubmitTime());
        }
        if(!ObjectUtils.isEmpty(video.getVideoMaker())) {
            queryWrapper = queryWrapper.like("video_maker",video.getVideoMaker());
        }
        if(!ObjectUtils.isEmpty(video.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code",video.getStatusCode());
        }
        if(!ObjectUtils.isEmpty(video.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete",video.getIsDelete());
        }
        if(!ObjectUtils.isEmpty(video.getAllotTime())) {
            queryWrapper = queryWrapper.like("allot_time",video.getAllotTime());
        }
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        queryWrapper.lambda().orderByDesc(Video::getCreateTime);
        //分配表中被分配人id为自己的draftIds
        Long cuurentUserId = videoService.selectUserIdByUsername(Utility.getCurrentUsername());
        QueryWrapper<Allot> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.in("allotNo_id", cuurentUserId);
        List<Allot> allotList = allotService.list(queryWrapper1);
        if (allotList.size() != 0) {
            List<Long> draftIds = new ArrayList<>();
            for (int i = 0; i < allotList.size(); i++) {
                draftIds.add(allotList.get(i).getDraftId());
            }
            queryWrapper
                    .in("tv.status_code", StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_FAILED)
                    .eq("tv.draft_type", StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE1)
                    .in("tv.draft_id",draftIds);//2026,2025
        }else{
            queryWrapper.eq("tv.status_code", StatusWriter.ERROR);
        }

        IPage<Video> pageInfo = videoService.listPage(page, queryWrapper);
        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("allotTimeSpace", allotTimeSpace);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix+"both/alreadyRefusedWorker";
    }

    /**
     * 组长被驳回
     * @param model
     * @param pageNo
     * @param pageSize
     * @param submitTimeSpace
     * @param allotTimeSpace
     * @param createTimeSpace
     * @param updateTimeSpace
     * @param video
     * @return
     */
    @RequestMapping("alreadyRefusedWorkerleader")
    public String alreadyRefusedWorkerleader(Model model,
                                             @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
        if(!ObjectUtils.isEmpty(video.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id",video.getDraftId());
        }
        if(!ObjectUtils.isEmpty(video.getDraftType())) {
            queryWrapper = queryWrapper.like("draft_type",video.getDraftType());
        }
        if(!ObjectUtils.isEmpty(video.getVideoUrl())) {
            queryWrapper = queryWrapper.like("video_url",video.getVideoUrl());
        }
        if(!ObjectUtils.isEmpty(video.getVideoLength())) {
            queryWrapper = queryWrapper.like("video_length",video.getVideoLength());
        }
        if(!ObjectUtils.isEmpty(video.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time",video.getSubmitTime());
        }
        if(!ObjectUtils.isEmpty(video.getVideoMaker())) {
            queryWrapper = queryWrapper.like("video_maker",video.getVideoMaker());
        }
        if(!ObjectUtils.isEmpty(video.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code",video.getStatusCode());
        }
        if(!ObjectUtils.isEmpty(video.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete",video.getIsDelete());
        }
        if(!ObjectUtils.isEmpty(video.getAllotTime())) {
            queryWrapper = queryWrapper.like("allot_time",video.getAllotTime());
        }
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.lambda().between(Video::getSubmitTime, DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        queryWrapper.lambda().orderByDesc(Video::getCreateTime);

        SysUser sysUser = pptService.getUserByUserName(Utility.getCurrentUsername());
        List<Check> groupByUserId = pptService.getChecksByIdPass(sysUser.getId());
        if(groupByUserId.size()!=0){
            queryWrapper.in("tv.draft_type",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE1);
            queryWrapper.in("tv.status_code",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_FAILED);
            IPage<Video> pageInfo = videoService.listPage(page, queryWrapper);

            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"both/alreadyRefusedWorker";
        }else{
            queryWrapper.lambda().eq(Video::getStatusCode, StatusWriter.ERROR);
            IPage<Video> pageInfo = videoService.page(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"both/alreadyRefusedWorker";
        }

//        //分配表中被分配人id为自己的draftIds
//        Long cuurentUserId = videoService.selectUserIdByUsername(Utility.getCurrentUsername());
//        QueryWrapper<Allot> queryWrapper1 = new QueryWrapper<>();
//        queryWrapper1.in("allotNo_id", cuurentUserId);
//        List<Allot> allotList = allotService.list(queryWrapper1);
//        if (allotList.size() != 0) {
//            List<Long> draftIds = new ArrayList<>();
//            for (int i = 0; i < allotList.size(); i++) {
//                draftIds.add(allotList.get(i).getDraftId());
//            }
//            queryWrapper
//                    .in("status_code", StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_FAILED)
//                    .eq("draft_type", StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE1);//2026
//            //wangyan 显示制作人名称
//            List<Video> draftList = videoMapper.selectList(queryWrapper);
//            Map<Long, String> types = new HashMap<Long, String>();
//            List<Long> ids = new ArrayList<>();
//            for (Video video1 : draftList) {
//                if (!ids.contains(video1.getVideoMaker())) {
//                    ids.add(video1.getVideoMaker());
//                    types.put(video1.getVideoMaker(), userService.selectByPrimaryKey(video1.getVideoMaker()).getUsername());
//                }
//            }
//            model.addAttribute("name", types);
//        }else{
//            queryWrapper.lambda().eq(Video::getStatusCode, StatusWriter.ERROR);
//        }
//
//        IPage<Video> pageInfo = videoService.page(page, queryWrapper);
//        model.addAttribute("submitTimeSpace", submitTimeSpace);
//        model.addAttribute("allotTimeSpace", allotTimeSpace);
//        model.addAttribute("searchInfo", video);
//        model.addAttribute("pageInfo", new PageInfo(pageInfo));
//        return prefix+"both/alreadyRefusedWorker";
    }

    /**
     *@author 孙祺至
     *@date 2019/12/21 0:08
     * 音视频校对组长
     * 进入未校对
     */
    @RequestMapping("VideoUnreview")
    public String VideoUnreview(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(videoService.leaderCheckIndex(video,pageNo,pageSize)));
        model.addAttribute("VedioGroup",videoService.setGroupStatus());
        return prefix+"check/VedioUnreview";
    }
    /**
     * @Author 张雪
     * @Description 音视频校对组长
     * 待抽查音转视
     * @Date 2019/12/21 13:55
     * @Param
     * @return
     **/
    @RequestMapping("unCheckAudioVideoLeader")
    public String unCheckAudioVideoLeader(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(videoService.leaderCheckIndex(video,pageNo,pageSize)));
        model.addAttribute("VedioGroup",videoService.setGroupStatus());
        return prefix+"leader/unCheckAudioVideo";
    }

    /**
     * @Author 刘辉
     * @Description 录屏制作人--审核中录屏
     * @Date 2019/12/17 15:48
     * @Param
     * @return
     **/
    @RequestMapping("unCheckVideo")
    public String unCheckVideo(Model model,@RequestParam(value = "pageNo",
            required = false, defaultValue = "1") Integer pageNo,
            String draftTitle,
            @RequestParam(value = "pageSize", required = false, defaultValue = "20")
                    Integer pageSize, String submitTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();

        //搜索稿件标题
        Draft draft=new Draft();
          Map<List<Long>,String> drafttitles=new HashMap<>();
        if (!ObjectUtils.isEmpty(draftTitle)) {
            QueryWrapper<Draft> queryWrappers = new QueryWrapper<Draft>();
            queryWrappers.like("draft_title", draftTitle);
            List<Draft> draftsList = draftService.list(queryWrappers);
            if (draftsList.size()!=0){
                queryWrapper.in("draft_id",draftsList.stream().map(Draft::getId).collect(Collectors.toList()));
            }else{
                queryWrapper.in("draft_id", -1);
            }
        }

        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);
        SysUser sysUser = pptService.getUserByUserName(Utility.getCurrentUsername());
        queryWrapper.eq("tv.video_maker",sysUser.getId());

        queryWrapper.in("tv.status_code",
        StatusRecordVideo.STATUS_RECORD_PPTTORECORD_UPLOADTO,
        StatusRecordVideo.STATUS_RECORD_BUTTJOJINT_SUCCESS,
        StatusRecordVideo.STATUS_RECORD_FUNCTIONARY_SUCCESS,
        StatusRecordVideo.STATUS_RECORD_COURSEREADER_SUCCESS,
        StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS,

        StatusRecordVideo.STATUS_RECORD_FUNCTIONARY_FAILED,
        StatusRecordVideo.STATUS_RECORD_COURSEREADER_FAILED,
        StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_FAILED,
        StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_FAILED
        );



        IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
        model.addAttribute("draftTitle",draftTitle);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix+"plate/unCheckVideo";
    }

    /**
     * @Author 刘辉
     * @Description 录屏制作人 -- 已通过录屏
     * @Date 2019/12/17 15:48
     **/
    @RequestMapping("passVideo")
    public String overPptVideoWorker(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1")
            Integer pageNo,String draftTitle,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "20")
                                             Integer pageSize, String submitTimeSpace,
                                     String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();

         //搜索稿件标题
        Draft draft=new Draft();
          Map<List<Long>,String> drafttitles=new HashMap<>();
        if (!ObjectUtils.isEmpty(draftTitle)) {
            QueryWrapper<Draft> queryWrappers = new QueryWrapper<Draft>();
            queryWrappers.like("draft_title", draftTitle);
            List<Draft> draftsList = draftService.list(queryWrappers);
            if (draftsList.size()!=0){
                queryWrapper.in("draft_id",draftsList.stream().map(Draft::getId).collect(Collectors.toList()));
            }else{
                queryWrapper.in("draft_id", -1);
            }
        }

        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);//倒叙
        SysUser sysUser = pptService.getUserByUserName(Utility.getCurrentUsername());
        queryWrapper.eq("tv.video_maker",sysUser.getId());
        queryWrapper.eq("tv.draft_type",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE2);
        queryWrapper.in("tv.status_code",
                StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_SUCCESS);//1026

        IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
        model.addAttribute("draftTitle",draftTitle);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix+"plate/passVideo";

    }
    /**
     *@author 刘辉
     *@Description 课程校对人 已通过录屏
     *@date 2020/1/7 14:25
     *
     */
    @RequestMapping("CpassVideo")
    public String oaverPptVideoWorker(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1")
            Integer pageNo,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "20")
                                             Integer pageSize, String submitTimeSpace,
                                     String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
      if (!ObjectUtils.isEmpty(submitTimeSpace)){
        queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);
        Long currentUserId = pptService.selectIdByUsername(Utility.getCurrentUsername());
        //分配表中id为自己的稿件id
        QueryWrapper<Allot> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("allotNo_id", currentUserId);
        List<Allot> allotList = allotService.list(queryWrapper1);
        List<Long> draftIds = new ArrayList<>();
        if (allotList.size()!=0){
            for (int i = 0; i < allotList.size(); i++) {
                draftIds.add(allotList.get(i).getDraftId());
            }
            queryWrapper.in("tv.draft_id", draftIds);
            queryWrapper.in("tv.status_code", StatusRecordVideo.STATUS_RECORD_COURSEREADER_SUCCESS);//1038
            queryWrapper.eq("tv.draft_type" , StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE2);

            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"ppt/cPassVideo";
        }else{
            queryWrapper.eq("tv.status_code", StatusWriter.ERROR);
            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"ppt/cPassVideo";
        }
    }
    /**
     * @Author 刘辉
     * @Description 录屏制作人   被驳回录屏
     * @Date 2019/12/17 15:48
     * @Param
     * @return
     **/
    @RequestMapping("refuseVideo")
    public String refuseVideo(Model model,String draftTitle,@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();

        //搜索稿件标题
        Draft draft=new Draft();
          Map<List<Long>,String> drafttitles=new HashMap<>();
        if (!ObjectUtils.isEmpty(draftTitle)) {
            QueryWrapper<Draft> queryWrappers = new QueryWrapper<Draft>();
            queryWrappers.like("draft_title", draftTitle);
            List<Draft> draftsList = draftService.list(queryWrappers);
            if (draftsList.size()!=0){
                queryWrapper.in("draft_id",draftsList.stream().map(Draft::getId).collect(Collectors.toList()));
            }else{
                queryWrapper.in("draft_id", -1);
            }
        }


        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);
        SysUser sysUser = pptService.getUserByUserName(Utility.getCurrentUsername());
        queryWrapper.eq("tv.video_maker",sysUser.getId());

        queryWrapper.in("tv.status_code", StatusRecordVideo.STATUS_RECORD_BUTTJOJINT_FAILED);//2028
        queryWrapper.eq("tv.draft_type",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE2);

        IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
        model.addAttribute("draftTitle",draftTitle);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix+"plate/refuseVideo";
    }



    /**
     * @Author 刘辉
     * @Description 被驳回录屏----录屏课程负责人
     * @Date 2019/12/17 15:48
     * @Param
     * @return
     **/
    @RequestMapping("refuseBossVideo")
    public String refuseBossVideo(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();

    if (!ObjectUtils.isEmpty(submitTimeSpace)){
        queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }
        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);
        List<Check> groupByUserId = pptService.getChecksByIdUnPass(pptService.getUserByUserName(Utility.getCurrentUsername()).getId());

        if(groupByUserId.size()!=0){
            queryWrapper.eq("tv.draft_type",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE2);
            queryWrapper.eq("tv.status_code",StatusRecordVideo.STATUS_RECORD_COURSEREADER_FAILED);

            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"plate/refuseBossVideo";
        }else{
            queryWrapper.eq("tv.status_code", StatusWriter.ERROR);
            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"plate/refuseBossVideo";
        }
    }





    /**
     * @Author 刘辉
     * @Description 课程校对人--已驳回录屏
     * @Date 2019/12/17 15:48
     * @Param
     * @return
     **/
    @RequestMapping("refusePPTVideo")
    public String refusePPTVideo(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
        if (!ObjectUtils.isEmpty(submitTimeSpace)){
        queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }

        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);
        Long currentUserId = pptService.selectIdByUsername(Utility.getCurrentUsername());
        //分配表中id为自己的稿件id
        QueryWrapper<Allot> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("allotNo_id", currentUserId);
        List<Allot> allotList = allotService.list(queryWrapper1);
        List<Long> draftIds = new ArrayList<>();
        if (allotList.size()!=0){
            for (int i = 0; i < allotList.size(); i++) {
                draftIds.add(allotList.get(i).getDraftId());
            }
            queryWrapper.in("tv.draft_id", draftIds);
            queryWrapper.eq("tv.status_code",
                    StatusRecordVideo.STATUS_RECORD_COURSEREADER_FAILED);//2038
            queryWrapper.eq("tv.draft_type",
                    StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE2);

            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"plate/refusePPTVideo";
        }else{
            queryWrapper.eq("tv.status_code", StatusWriter.ERROR);
            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"plate/refusePPTVideo";
        }
    }




    /**
     * 添加跳转页面
     * @return
     */
    @RequestMapping("plateToReason")
    public String plateToReason(Long id,Model model){
        log.info("id====>{}",id);
        model.addAttribute("id",id);
        return prefix+"plate/reason";
    }
    /**
     * oss 文件下载
     * @param pptId ppt主键
     */
    @PostMapping(value = "ossDownloadFile",produces="application/json")
    public void downloadFile(@RequestParam("pptId") String pptId, HttpServletResponse response) {
        log.info("pptId===================== "+pptId);

        String  path = videoService.getById(Long.valueOf(pptId)).getVideoUrl();
        log.info("path===================== "+path);
        log.info("开始文件下载===================== ");
        OssUtil.download2FileByStream(path,response);
    }
    /**
     * @Author 张雪
     * @Description 查看驳回理由
     * @Date 2019/12/21 14:37
     * @Param
     * @return
     **/
    @GetMapping("lookReason/{id}")
    public String afailedReasonBefore(@PathVariable("id") Long id, Model model) {
        List<Check> checkById = pptService.getCheckById(id);
        for (int i = 0; i < checkById.size(); i++) {
            if (videoService.getById(id).getLastOperator()==checkById.get(i).getUserId()){
                model.addAttribute("check", checkById.get(i).getReason());
                return prefix + "lookReasonBefore";
            }
        }
        return prefix + "lookReasonBefore";
    }
    /**
     * @param
     * @return
     * @author 孙祺至
     * @date 2019年12月16日16:47:28
     * PPT录屏制作人查看驳回理由
     */
    @GetMapping("videofailedReasonBefore/{id}")
    public String videofailedReasonBefore(@PathVariable("id") Long id, Model model) {
        log.info("===============进来了我=========="+id);
        List<Check> checkById = pptService.getCheckById(id);
        if (checkById.size()!=0){
            for (int i = 0; i < checkById.size(); i++) {
                if (videoService.getById(id).getLastOperator()==checkById.get(i).getUserId()
                        &&checkById.get(i).getIsPass()==true){
                    model.addAttribute("check", checkById.get(i).getReason());
                    return prefix + "FailedReasonBefore";
                }
            }
            return prefix + "FailedReasonBefore";
        }else {
            return prefix + "FailedReasonBefore";
        }
    }

    @GetMapping("failedBefore/{id}")
    public String failedAll(@PathVariable("id") Long id, Model model) {
        log.info("===========failedBefore=============>{}", id);
        model.addAttribute("id", id);
        return prefix + "SectionLeaderFailedReason";
    }




    @GetMapping("FfailedReasonBefore/{id}")
    public String FfailedReasonBefore(@PathVariable("id") Long id, Model model) {
        List<Check> checkById = pptService.getCheckById(id);
        log.info("checkById==================>>{}",checkById);
        log.info("当前登录人：==============>>{}",pptService.getUserByUserName(Utility.getCurrentUsername()).getId());
        log.info("true Or false???>>>>>>{}",pptService.getUserByUserName(Utility.getCurrentUsername()).getId()==checkById.get(0).getUserId());
        for (int i = 0; i < checkById.size(); i++) {
            if (pptService.getUserByUserName(Utility.getCurrentUsername()).getId()==checkById.get(i).getUserId()
                    &&checkById.get(i).getIsPass()==true
                    &&checkById.get(i).getOverStatusCode().equals(StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_FAILED)){
                model.addAttribute("check", checkById.get(i).getReason());
                return prefix + "FailedReasonBefore";
            }
        }
        return prefix + "FailedReasonBefore";
    }
/**
 *@author 刘辉
 *@date 2020/1/7 10:35
 * 课程校对人-- 被驳回录屏
 */
    @RequestMapping("befailed")
    public String befailed(Model model, @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();

         if (!ObjectUtils.isEmpty(submitTimeSpace)){
        queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }

        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);
        Long currentUserId = pptService.selectIdByUsername(Utility.getCurrentUsername());
        //分配表中id为自己的稿件id
        QueryWrapper<Allot> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("allotNo_id", currentUserId);
        List<Allot> allotList = allotService.list(queryWrapper1);
        List<Long> draftIds = new ArrayList<>();
        if (allotList.size()!=0){
            for (int i = 0; i < allotList.size(); i++) {
                draftIds.add(allotList.get(i).getDraftId());
            }
            queryWrapper.in("tv.draft_id", draftIds);
            queryWrapper.in("tv.status_code", StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_FAILED);//2025
            queryWrapper.eq("tv.draft_type" , StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE2);

            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"SectionLeaderBeFailed";
        }else{
            queryWrapper.eq("tv.status_code", StatusWriter.ERROR);
            IPage<Video> pageInfo = videoMapper.listPagess(page, queryWrapper);
            model.addAttribute("submitTimeSpace", submitTimeSpace);
            model.addAttribute("searchInfo", video);
            model.addAttribute("pageInfo", new PageInfo(pageInfo));
            return prefix+"SectionLeaderBeFailed";
        }
    }

    @GetMapping("BefailedReasonBefore/{id}")
    public String BefailedReasonBefore(@PathVariable("id") Long id, Model model) {
        List<Check> checkById = pptService.getCheckById(id);
        if (checkById.size()!=0){
            for (int i = 0; i < checkById.size(); i++) {
                if (videoService.getById(id).getLastOperator()==checkById.get(i).getUserId()&&checkById.get(i).getIsPass()==true){
                    model.addAttribute("check", checkById.get(i).getReason());
                    return prefix + "FailedReasonBefore";
                }
            }
            return prefix + "FailedReasonBefore";
        }
        return prefix + "FailedReasonBefore";
    }

    /**
     * @Author 牛英健
     * @Description 制作人 审核中稿件转视
     * @Date 2019/12/17 15:48
     * @Param
     * @return
     **/
    @RequestMapping("checkingVideoTow")
    public String checkingVideoTow(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                     @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                     String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
        if(!ObjectUtils.isEmpty(video.getDraftId())) {

            queryWrapper = queryWrapper.like("draft_id",video.getDraftId());
        }
        if(!ObjectUtils.isEmpty(video.getDraftType())) {
            queryWrapper = queryWrapper.like("draft_type",video.getDraftType());
        }
        if(!ObjectUtils.isEmpty(video.getVideoUrl())) {
            queryWrapper = queryWrapper.like("video_url",video.getVideoUrl());
        }
        if(!ObjectUtils.isEmpty(video.getVideoLength())) {
            queryWrapper = queryWrapper.like("video_length",video.getVideoLength());
        }
        if(!ObjectUtils.isEmpty(video.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time",video.getSubmitTime());
        }
        if(!ObjectUtils.isEmpty(video.getVideoMaker())) {
            queryWrapper = queryWrapper.like("video_maker",video.getVideoMaker());
        }
        if(!ObjectUtils.isEmpty(video.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code",video.getStatusCode());
        }
        if(!ObjectUtils.isEmpty(video.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete",video.getIsDelete());
        }
        if(!ObjectUtils.isEmpty(video.getAllotTime())) {
            queryWrapper = queryWrapper.like("allot_time",video.getAllotTime());
        }

        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }

        String username = Utility.getCurrentUsername();
        queryWrapper.lambda().eq(Video::getVideoMaker, userService.selectByUsername(username).getId());
        queryWrapper.eq("tv.status_code", StatusRecordVideo.STATUS_VIDEO_AUDIOTOVIDEO_UPLOAD);
//        queryWrapper.lambda().orderByDesc(Video::getUpdateTime);
        IPage<Video> pageInfo = videoService.listPage(page, queryWrapper);
        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix + "draft/checkingVideo";

    }


    /**
     * @Author 牛英健
     * @Description 音转视校对人--已通过音转视
     * @Date 2019/12/18 15:48
     * @Param
     * @return
     **/
    @RequestMapping("overVideoTow")
    public String overVideoTow(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1")
            Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                            String submitTimeSpace, String allotTimeSpace, String createTimeSpace, String updateTimeSpace, Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
        if(!ObjectUtils.isEmpty(video.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id",video.getDraftId());
        }
        if(!ObjectUtils.isEmpty(video.getDraftType())) {
            queryWrapper = queryWrapper.like("draft_type",video.getDraftType());
        }
        if(!ObjectUtils.isEmpty(video.getVideoUrl())) {
            queryWrapper = queryWrapper.like("video_url",video.getVideoUrl());
        }
        if(!ObjectUtils.isEmpty(video.getVideoLength())) {
            queryWrapper = queryWrapper.like("video_length",video.getVideoLength());
        }
        if(!ObjectUtils.isEmpty(video.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time",video.getSubmitTime());
        }
        if(!ObjectUtils.isEmpty(video.getVideoMaker())) {
            queryWrapper = queryWrapper.like("video_maker",video.getVideoMaker());
        }
        if(!ObjectUtils.isEmpty(video.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code",video.getStatusCode());
        }
        if(!ObjectUtils.isEmpty(video.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete",video.getIsDelete());
        }
        if(!ObjectUtils.isEmpty(video.getAllotTime())) {
            queryWrapper = queryWrapper.like("allot_time",video.getAllotTime());
        }

        String username = Utility.getCurrentUsername();
        queryWrapper.lambda().eq(Video::getVideoMaker, userService.selectByUsername(username).getId());

        if (!ObjectUtils.isEmpty(submitTimeSpace)){
            queryWrapper.between("tv.submit_time", DateUtil.getStart(submitTimeSpace)
                    ,DateUtil.getEnd(submitTimeSpace).plusDays(1));
        }

        //分配表中被分配人id为自己的draftIds
        Long cuurentUserId = videoService.selectUserIdByUsername(Utility.getCurrentUsername());
        QueryWrapper<Allot> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.in("allotNo_id", cuurentUserId);
        List<Allot> allotList = allotService.list(queryWrapper1);
        if (allotList.size() != 0) {
            List<Long> draftIds = new ArrayList<>();
            for (int i = 0; i < allotList.size(); i++) {
                draftIds.add(allotList.get(i).getDraftId());
            }

            queryWrapper.in("tv.status_code", StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_SUCCESS,
                    StatusRecordVideo.STATUS_VIDEO_RECORD_AUVELEADER_SUCCESS);//1023音频校对人通过
            queryWrapper.eq("tv.draft_type",StatusRecordVideo.STATUS_VIDEO_RECORD_AUVEFINALLEADER_DRAFT_TYPE1);
            queryWrapper.in("tv.draft_id", draftIds);

        }else{
            queryWrapper.eq("tv.status_code", StatusWriter.ERROR);
        }

        IPage<Video> pageInfo = videoService.listPage(page, queryWrapper);

        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("allotTimeSpace", allotTimeSpace);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix+"draft/overVideo";
    }

    /**
     * @Author 牛英健
     * @Description 制作人--被驳回音转视
     * @Date 2019/12/18 15:48
     * @Param
     * @return
     **/
    @RequestMapping("refusedMakerTow")
    public String refusedMakerTow(Model model,@RequestParam(value = "pageNo", required = false, defaultValue = "1")
            Integer pageNo,@RequestParam(value = "pageSize", required = false, defaultValue = "20")
                                       Integer pageSize, String submitTimeSpace,
                               String allotTimeSpace, String createTimeSpace, String updateTimeSpace,
                               Video video) {
        Page<Video> page = new Page<Video>(pageNo, pageSize);
        QueryWrapper<Video> queryWrapper = new QueryWrapper<Video>();
        if(!ObjectUtils.isEmpty(video.getDraftId())) {
            queryWrapper = queryWrapper.like("draft_id",video.getDraftId());
        }
        if(!ObjectUtils.isEmpty(video.getDraftType())) {
            queryWrapper = queryWrapper.like("draft_type",video.getDraftType());
        }
        if(!ObjectUtils.isEmpty(video.getVideoUrl())) {
            queryWrapper = queryWrapper.like("video_url",video.getVideoUrl());
        }
        if(!ObjectUtils.isEmpty(video.getVideoLength())) {
            queryWrapper = queryWrapper.like("video_length",video.getVideoLength());
        }
        if(!ObjectUtils.isEmpty(video.getSubmitTime())) {
            queryWrapper = queryWrapper.like("submit_time",video.getSubmitTime());
        }
        if(!ObjectUtils.isEmpty(video.getVideoMaker())) {
            queryWrapper = queryWrapper.like("video_maker",video.getVideoMaker());
        }
        if(!ObjectUtils.isEmpty(video.getStatusCode())) {
            queryWrapper = queryWrapper.like("status_code",video.getStatusCode());
        }
        if(!ObjectUtils.isEmpty(video.getIsDelete())) {
            queryWrapper = queryWrapper.like("is_delete",video.getIsDelete());
        }
        if(!ObjectUtils.isEmpty(video.getAllotTime())) {
            queryWrapper = queryWrapper.like("allot_time",video.getAllotTime());
        }

        queryWrapper.lambda().orderByDesc(Video::getCreateTime);
        //分配表中被分配人id为自己的draftIds
        Long cuurentUserId = videoService.selectUserIdByUsername(Utility.getCurrentUsername());
        QueryWrapper<Allot> queryWrapper1 = new QueryWrapper<>();
        log.info("cuurentUserId========"+cuurentUserId);
        queryWrapper1.in("allotNo_id", cuurentUserId);
        List<Allot> allotList = allotService.list(queryWrapper1);
        if (allotList.size() > 0) {
            List<Long> draftIds = new ArrayList<>();
            for (int i = 0; i < allotList.size(); i++) {
                draftIds.add(allotList.get(i).getDraftId());
            }
            List<Audio> audioList = audioService.list(new QueryWrapper<Audio>().lambda()
                    .in(Audio::getDraftId,draftIds));
            if(!CollectionUtils.isEmpty(audioList)){
                queryWrapper.in("tv.draft_id",audioList.stream().map(a->a.getDraftId()).collect(Collectors.toList()));
            }else{
                queryWrapper.in("tv.draft_id",-1L);
            }
            queryWrapper.in("tv.status_code", StatusRecordVideo.STATUS_VIDEO_AUDIOREADER_FAILED);//2023音频校对人驳回

        }else{
            queryWrapper.eq("tv.status_code", StatusWriter.ERROR);

        }
        IPage<Video> pageInfo = videoService.listPage(page, queryWrapper);

        model.addAttribute("submitTimeSpace", submitTimeSpace);
        model.addAttribute("allotTimeSpace", allotTimeSpace);
        model.addAttribute("searchInfo", video);
        model.addAttribute("pageInfo", new PageInfo(pageInfo));
        return prefix+"draft/failMaker";
    }

}
